<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<div id="container">

</div>
</body>
</html>


<!--引入react核心库-->
<script type="text/javascript" src="../Js/react.development.js"></script>
<!--引入react-dom库,用于支持react操作dom-->
<script type="text/javascript" src="../Js/react-dom.development.js"></script>
<!--引入babel库,用于将jsx转成js-->
<script type="text/javascript" src="../Js/babel.min.js"></script>
<!--引入prop-types库,用于将对props进行类型限制-->
<script type="text/javascript" src="../Js/prop-types.js"></script>

<script type="text/babel">//此处一定要写text/babel，将jsx转成js

class  Life extends React.Component{

    state={
        opacity:1
    }

    // 组件挂载完毕
    componentDidMount(){
        this.timer=setInterval(()=>{
            console.log("@")
            let opacity=this.state.opacity

            opacity-=0.2
            if(opacity<=0){
                opacity=1
            }

            this.setState({
                opacity
            })
        },200)
    }

    // 组件卸载前
    componentWillUnmount(){
        clearInterval(this.timer)
    }

    // 销毁组件
    death=()=>{
        ReactDOM.unmountComponentAtNode(document.getElementById("container"))
    }



    render(){
        return(
            <div>
                <h1 style={{opacity:this.state.opacity}}>我是示例文字</h1>
                <button onClick={this.death}>销毁组件</button>
            </div>
        )
    }
}

ReactDOM.render(<Life/>,document.getElementById("container"))

</script>